package com.mall.search.web;

import com.mall.search.service.SearchService;
import com.mall.search.vo.SearchParam;
import com.mall.search.vo.SearchResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author: 谢君臣
 * @Date: 2022/7/31-13:19
 * @version: 1.0
 * @function:
 */
@Controller
@Slf4j
public class IndexController {

    @Resource
    private SearchService searchService;

    @GetMapping({"/","/index","search.html","/list.html"})
    public ModelAndView indexPage(SearchParam searchParam, HttpServletRequest request){
        log.debug("进入首页页");
        String queryString = request.getQueryString();
        searchParam.set_queryString(queryString);
        SearchResult searchResult = searchService.search(searchParam);
        ModelAndView mav = new ModelAndView("list");
        mav.addObject(searchResult);
        log.debug("" + mav);
        return mav;
    }

}
